﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Core;
using SmartSpace;
using SmartSapce.ServiceLocation;

namespace SmartSpace.WebApp._console.core
{
    public partial class role_list : System.Web.UI.Page
    {
        private Guid _selectedRoleId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                _selectedRoleId = new Guid(Request.QueryString["id"]);
            }

            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                PagedList<Role> roles = service.GetRoles(0,999);

                if (roles.Count > 0 && _selectedRoleId == default(Guid))
                {
                    _selectedRoleId = roles[0].Id;
                }
                _ctlSubViewFrame.Attributes["src"] = string.Format("role-user-list.aspx?id={0}", _selectedRoleId);

                _ctlGridRole.DataSource = roles;
                _ctlGridRole.DataBind();
            }
        }

        public bool IsSelected(object roleId)
        {
            if (_selectedRoleId == (Guid)roleId)
            {
                return true;
            }
            return false;
        }
    }
}